import _ from "lodash";
import {useEffect} from "react";
import {Breadcrumb, Card, Empty} from "antd";
import {useNavigate, useParams} from "react-router-dom";
import {typeList} from "@/utils/data";
import BaseTable from "./BaseTable";
import "./index.less";

const Content = () => {
    const {id} = useParams();
    const item = _.find(typeList, {id: Number(id)});
    const nav = useNavigate();
    useEffect(() => {
        const isLogin = localStorage.getItem("admin") || false;
        if (!isLogin) {
            nav("/", {replace: true});
        }
    }, [nav]);

    return (
        <div className="page-content">
            {_.isEmpty(item) && !id ? (
                <Empty description="当前路径不存在" />
            ) : (
                <Card className="wrapper">
                    <Breadcrumb
                        items={[
                            {
                                title: "首页",
                                href: "/home",
                            },
                            {
                                title: item?.name,
                            },
                        ]}
                    />
                    {/* <Search
                        placeholder="请输入"
                        allowClear
                        className="search"
                        enterButton="查询"
                        size="large"
                        onSearch={handleSearch}
                    /> */}
                    <BaseTable name={item?.name} />
                </Card>
            )}
        </div>
    );
};

export default Content;
